#pragma once

#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <cstring>

#define FIFO_FILE "./fifo"   // 创建管道的路径
#define MODE 0666            // 管道创建的权限
#define MAX_BUFFER_SIZE 1024 // 管道读写的最大缓存大小

enum // 出错码
{
    FIFO_CREATE_ERROR = 1,
    FIFO_OPEN_ERROR = 2,
    FIFO_WRITE_ERROR = 3,
    FIFO_READ_ERROR = 4,
    FIFO_CLOSE_ERROR = 5,
    FIFO_DELETE_ERROR = 6
};
class FIFO
{
public:
    FIFO()
    {
        int n = mkfifo(FIFO_FILE, MODE);
        if (n == -1)
        {
            perror("mkfifo error");
            exit(FIFO_CREATE_ERROR);
        }
    }
    ~FIFO()
    {
        int m = unlink(FIFO_FILE);
        if (m == -1)
        {
            perror("unlink error");
            exit(FIFO_DELETE_ERROR);
        }
    }
};